<!doctype html>
<html>
<head>
<template source='TPL:admin.common.head' />
</head>
<body>
<div class="wrap">	
	
	
<!--添加模板-->

	<div class="nav">
		<div class="return"><a href="{@url:design/module/run?type=$isapi}">返回上一级</a></div>
		<ul class="cc">
		<!--# if ($isdata){ #-->
			<li><a href="{@url:design/data/run?moduleid=$moduleid}">显示数据</a></li>
			<li><a href="{@url:design/data/push?moduleid=$moduleid}">推送审核</a></li>
		<!--# } #-->
			<li class="current"><a href="{@url:design/property/edit?moduleid=$moduleid}">属性</a></li>
		<!--# if ($isdata){ #-->
			<li><a href="{@url:design/template/edit?moduleid=$moduleid}">模板</a></li>
		<!--# } #-->
		</ul>
	</div>
	<div class="h_a">属性</div>
	<form class="J_ajaxForm" action="{@url:design/property/doedit?_json=1}" method="post">
	<div class="design_ct">
		<dl class="cc">
			<dt>数据模型：</dt>
			<dd>
				<select class="select_2 mr10" name="model_type" id="J_select_model_type">
				<!--# foreach ($types as $k=>$v){#-->
					<option value="{$k}" {@Pw::isSelected($modelInfo['type'] == $k)}>{$v}</option>
				<!--# } #-->
				</select>
				<select class="select_2 mr10" name="model" id="J_select_model">
				<!--# foreach ($models[$modelInfo['type']] as $v){	#-->
						<option value="{$v['model']}" {@Pw::isSelected($model == $v['model'])}>{$v['name']}</option>
				<!--# } #-->
				</select>
				<!--# if ($isedit){ #-->
					<p class="red">切换数据模型可能导致当前模板不可用，请重新设置模板</p>
				<!--# } #-->
			</dd>
		</dl>

		<template source='TPL:design.segment.property' load='true' />
	</div>
	<div class="btn_wrap">
		<div class="btn_wrap_pd">
			<button class="btn btn_submit J_ajax_submit_btn" type="submit" >提交</button>
			<input type="hidden"  name="moduleid" value="{$moduleid}">
		</div>
	</div>
	</form>

	
</div>
<template source='TPL:admin.common.footer' />
<script>
$(function(){
	var select_model = $('#J_select_model'),
		DESIGN_MODELS = {@$models|json};

	$('#J_select_model_type').on('change', function(e){
		//模块属性 数据模型
		var data = DESIGN_MODELS[this.value],
			arr = [];
		if(data) {
			for (i = 0, len = data.length; i<len; i++) {
				arr.push('<option value="'+ data[i].model +'">'+ data[i].name +'</option>')
			}
			select_model.html(arr.join('')).show();

			if (select_model.val()) {
				location.href = changeURLPar(location.href, 'model', select_model.val());
			}
 		}else{
			select_model.hide().html('');
		}
	});

	select_model.on('change', function(e){
		//更新数据模块
		if(this.value) {
			location.href = changeURLPar(location.href, 'model', this.value);
		}
		
	});

	//url参数替换
	function changeURLPar(destiny, par, par_value) {
		var pattern = par+'=([^&]*)';
		var replaceText = par+'='+par_value;

		if(destiny.match(pattern)) {
			var tmp = '/\\'+par+'=[^&]*/';
			tmp = destiny.replace(eval(tmp), replaceText);
			return (tmp);
		}else{
			if(destiny.match('[\?]')) {
				return destiny+'&'+ replaceText;
			}else{
				return destiny+'?'+replaceText;
			}
		}

		return destiny+'\n'+par+'\n'+par_value;
	}

	//地区组件
	if($('a.J_region_change').length) {
		Wind.use('region', function(){
			$('a.J_region_change').region({
				regioncancl : true
			});
		});
	}

});
</script>
</body>
</html>